using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SavePoint : MonoBehaviour, IInteractable {

    [Header("广播")]
    public VoidEventSO saveDataEvent;       // 保存游戏数据的事件广播

    public SpriteRenderer spriteRenderer;   // spriteRenderer组件
    public GameObject lightObj;             // 灯光
    public Sprite lightSprite;              // 存档点图标亮起
    public Sprite darkSprite;               // 存档点图标灰暗
    public bool isDone;                     // 是否已经操作过了

    private void Awake() {
        isDone = false;
    }

    private void OnEnable() {
        spriteRenderer.sprite = isDone ? lightSprite : darkSprite;
        lightObj.SetActive(isDone);
    }

    public void TriggerAction() {
        if (!isDone) {
            spriteRenderer.sprite = lightSprite;
            isDone = true;
            lightObj.SetActive(true);
            gameObject.tag = "Untagged";

            // TODO: 保存数据
            saveDataEvent.RaiseEvent();
        }
    }

}